import {
  response,
  errorHandle,
  url
} from './response';

const getToken = () => {
  return wx.getStorageSync('auth');
}
/**
 * 添加配置
 * @param {*} data 
 * @param {*} successCallback 
 */
export const add = (data, successCallback) => {
  wx.request({
    url: `${url}/settings/add`,
    method: 'post',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}
/**
 * 移除配置
 * @param {*} data 
 * @param {*} successCallback 
 */
export const remove = (data, successCallback) => {
  wx.request({
    url: `${url}/settings/remove`,
    method: 'post',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}
/**
 * 查询单一配置
 * @param {*} data 
 * @param {*} successCallback 
 */
export const _get = (data, successCallback) => {
  wx.request({
    url: `${url}/settings/get`,
    method: 'get',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}
/**
 * 修改配置
 * @param {*} data 
 * @param {*} successCallback 
 */
export const update = (data, successCallback) => {
  wx.request({
    url: `${url}/settings/update`,
    method: 'post',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}
/**
 * 查询配置列表
 * @param {*} data 
 * @param {*} successCallback 
 */
export const list = (data, successCallback) => {
  wx.request({
    url: `${url}/settings/list`,
    method: 'get',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}

export const productList = (data,successCallback)=>{
  wx.request({
    url: `${url}/finishProduct/settings/list`,
    method: 'get',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}

export const productRemove = (data, successCallback)=>{
  wx.request({
    url: `${url}/finishProduct/settings/remove`,
    method: 'post',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}
export const productSearch = (data,successCallback)=>{
  wx.request({
    url: `${url}/finishProduct/settings/search`,
    method: 'get',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}

export const productAdd = (data, successCallback)=>{
  wx.request({
    url: `${url}/finishProduct/settings/add`,
    method: 'post',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}
export const productUpdate = (data, successCallback)=>{
  wx.request({
    url: `${url}/finishProduct/settings/update`,
    method: 'post',
    data,
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}
export const productById = (id, successCallback)=>{
  wx.request({
    url: `${url}/finishProduct/settings/${id}`,
    method: 'get',
    header: {
      'x-user-agent': 'miniprogram',
      'x-auth-token': getToken()
    },
    success(res) {
      response(res, successCallback);
    },
    fail: (res) => {
      errorHandle(res.errMsg);
    }
  })
}